package StudyCode.summary.zipfile;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.zip.GZIPOutputStream;

/**
 * 版权所有 科技与人文(www.tah1986.com)
 */
public class CompressDataBytesByGzipAlgorithm {
	public static byte[] gzip(byte[] data) throws IOException {
		if (data == null) {
			return data;
		}

		ByteArrayOutputStream out = new ByteArrayOutputStream();
		GZIPOutputStream gos = null;
		try {
			gos = new GZIPOutputStream(out);
			gos.write(data);
		} finally {
			if (gos != null) {
				gos.close();
			}
		}

		return out.toByteArray();
	}
}
